// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ------------------------------------------------------------------
// Modification history:
// feature: change E2E packet format
// feature: agent for vbs
// feature: destination order support by reception timestamp
// feature: E2E protection
// ------------------------------------------------------------------

#include <xmlparser/qos/XMLDataReaderQos.hpp>

namespace vbsutil {
namespace xmlparser {

RTPS_DllAPI const DataReaderQos DATAREADER_QOS_DEFAULT;

ReaderQos DataReaderQos::get_readerqos(const SubscriberQos& sqos) const {
    ReaderQos qos;
    qos.m_durability = durability();
    qos.m_deadline = deadline();
    qos.m_liveliness = liveliness();
    qos.m_reliability = reliability();
    qos.m_partition = sqos.partition();
    qos.m_ownership = ownership();
    qos.m_disablePositiveACKs = reliable_reader_qos().disable_positive_ACKs;
    qos.m_e2eProtecion = e2e_protection();
    qos.m_isMultiSend = send_multi();
    qos.m_destinationOrder = destination_order();
    qos.m_ipc_mode = ipc_mode();
    qos.m_agent_flag = agent_flag();

    return qos;
}

const DataReaderQos& getDefaultDataReaderQos() {
    return DATAREADER_QOS_DEFAULT;
}

void DataReaderQos::exportDataReaderQosInfo() const {
    logDebug(
        SUBSCRIBER,
        "DataReaderQosInfo"
            << " history kind: " << (int)history_.kind << " depth: " << history_.depth << std::endl
            << " max_samples: " << resource_limits_.max_samples << " max_instances: " << resource_limits_.max_instances
            << " max_samples_per_instance: " << resource_limits_.max_samples_per_instance << " allocated_samples: "
            << resource_limits_.allocated_samples << " extra_samples: " << resource_limits_.extra_samples << std::endl
            << " durability kind: " << (int)durability_.kind << std::endl
            << " reliability kind: " << (int)reliability_.kind
            << " max_blocking_time: " << reliability_.max_blocking_time << std::endl
            << " deadline period: " << deadline_.period << std::endl
            << "enable:" << e2e_protection_.enabled << " needCheckEnableFlag: " << e2e_protection_.needCheckEnableFlag
            << " MinDataLength: " << e2e_protection_.MinDataLength << " MaxDataLength: "
            << e2e_protection_.MaxDataLength << " MaxDeltaCounter: " << e2e_protection_.MaxDeltaCounter << std::endl
            << " lifespan duration: " << lifespan_.duration << std::endl
            << " ownership kind: " << (int)ownership_.kind << std::endl
            << " liveliness kind: " << (int)liveliness_.kind << " lease_duration: " << liveliness_.lease_duration
            << " announcement_period: " << liveliness_.announcement_period << std::endl
            << " times initialAcknackDelay: " << reliable_reader_qos_.times.initialAcknackDelay
            << " heartbeatResponseDelay: " << reliable_reader_qos_.times.heartbeatResponseDelay << std::endl
            << " endpoint ignore_non_matching_locators: " << endpoint_.ignore_non_matching_locators
            << " user_defined_id: " << endpoint_.user_defined_id << " entity_id: " << endpoint_.entity_id
            << " history_memory_policy: " << (int)endpoint_.history_memory_policy << " external_unicast_locators: "
            << endpoint_.external_unicast_locators << " unicast_locator_list: " << endpoint_.unicast_locator_list
            << " multicast_locator_list: " << endpoint_.multicast_locator_list
            << " remote_locator_list: " << endpoint_.remote_locator_list << std::endl
            << " properties: " << properties_.properties() << " binary_properties_: " << properties_.binary_properties()
            << std::endl);
}
}  // namespace xmlparser
}  // namespace vbsutil
